<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Services\GeTuiService;
use Illuminate\Http\Request;
use App\V3\V3_1\Models\SystemConfigModel;
use App\Helper\DBRSAUtil;
use Illuminate\Support\Facades\Redis;

class TestController extends Controller
{
    public function test(Request $request){
//        $this->log('test',['test'=>44,'xixi'=>'asdfa']);
//        Redis::SETEX('user_id_7',20,7);
//        var_dump(TimeUtil::convertDateSignToUnix());
//        return $this->fail();
//        echo $this->getMainUserId();
//        TestService::test();
//        print_r($request->all());
//        dump('hfahsdhsdsgfgsdhfdf');

    }

    /**
     * token生成方案测试
     * change 在 2021/10/11 15:09 创建
     * @param Request $request
     */
    public function token(){

        $userId = 1;//子账号(账号类型为主账号时子账号同主账号)
        $mainUserId = 1;//主账号
        $userType = 0;//账号类型： 0-主 1-子
        $type = 1;//登录端：1-安卓 2-ios 3-pc 4-微信小程序 5-抖音小程序

        $arr = [
            'userId'=>$userId,
            'mainUserId'=>$mainUserId,
            'userType'=>$userType,
            'type'=>$type
        ];
        $arr = json_encode($arr);
        $public_key = SystemConfigModel::getConfigValue('public');
        $token = DBRSAUtil::rsaEncrypt($arr, $public_key);
        echo $token;die;
        //登录过期设置（15天）
        Redis::SETEX('user_id_'.$userId.'_'.$type,86400*15,$userId);
    }

    public function push() {
        $result = GeTuiService::push('库存不足', '库存不足啦', '4b09eb5f74e8f67f4d580d38e8b47d93');
        var_dump($result);
    }

}
